home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / PART_F / VIEWMAN / SUBS.S < prev    next >
Encoding:
Text File  |  2001-02-10  |  44.6 KB  |  2,265 lines

  1. *
  2. *    SUBS.S
  3. *
  4.     .include    "equates.s"
  5. *
  6.     .text
  7. *
  8. *
  9. *
  10. *
  11. *
  12. *
  13. ctrlkey:
  14.     movem.l    a0/d0-d4,-(sp)
  15.     move.w    keyz,d5
  16.     eor.w    d2,d5
  17.     move.w    d2,keyz        ;any edges
  18.     btst.l    #LEFTSHIFT,d5    ;edge on left shift?
  19.     beq    ck0        ;br if no--do nothing
  20. *
  21.     btst.l    #LEFTSHIFT,d2    ;is left shift key down?
  22.     bne    ck1        ;br if leading edge on left shift
  23. *
  24. *  trailing edge on left shift--exit contain mode
  25. *
  26.     move.w    d2,-(sp)
  27.     movem.w    xmin_clp,d0-d3
  28.     movem.w    d0-d3,Mclpxmn    ;set contain world motion variables
  29.     move.w    (sp)+,d2
  30.     bra    ck0
  31. *
  32. *  leading edge on left shift--enter contain mode
  33. *
  34. ck1:
  35.     movem.w    d2/d5,-(sp)
  36. *
  37. *  request for contain function--compute new clip rectangle
  38. *
  39.     movem.w    xmin_clp,d0-d3    ;get current motion clip
  40.     move.w    d0,d7
  41. *  adjust xmin_clp
  42.     move.w    bsh_wid,d5
  43.     subq.w    #1,d5
  44.     sub.w    xoffset(a5),d5
  45.     bmi    ck00
  46.     add.w    d5,d0        ;adjust xmin_clp
  47. ck00:
  48. *  adjust xmax_clp
  49.     sub.w    xoffset(a5),d7
  50.     add.w    w_wid(a5),d7
  51.     sub.w    bsh_wid,d7
  52.     addq.w    #1,d7        ;take the smaller
  53.     cmp.w    d7,d2
  54.     ble    ck01
  55.     move.w    d7,d2
  56. ck01:
  57. *
  58.     move.w    d1,d7
  59. *  adjust ymin_clp
  60.     move.w    bsh_hite,d5
  61.     sub.w    #1,d5
  62.     sub.w    yoffset(a5),d5
  63.     bmi    ck02
  64.     add.w    d5,d1        ;adjust xmin_clp
  65. ck02:
  66. *  adjust ymax_clp
  67.     sub.w    yoffset(a5),d7
  68.     add.w    w_hite(a5),d7
  69.     sub.w    bsh_hite,d7
  70.     addq.w    #1,d7        ;take the smaller
  71.     cmp.w    d7,d3
  72.     ble    ck03
  73.     move.w    d7,d3
  74. ck03:
  75.     movem.w    bsh_x,d4-d5
  76. *
  77.     cmp    d4,d2
  78.     blt    ck04
  79. *
  80.     cmp    d5,d3
  81.     blt    ck04
  82. *
  83.     sub.w    wx(a5),d4
  84.     add.w    xoffset(a5),d4
  85.     bmi    ck04
  86. *
  87.     sub.w    wy(a5),d5
  88.     add.w    yoffset(a5),d5
  89.     bmi    ck04
  90. *
  91.     movem.w    d0-d3,Mclpxmn    ;set contain world motion variables
  92. ck04:
  93.     movem.w    (sp)+,d2/d5
  94. *
  95. *
  96. ck0:
  97.     btst.l    #RITESHIFT,d5    ;edge on right shift?
  98.     beq    ck0x        ;br if no--do nothing
  99. *
  100.     btst.l    #RITESHIFT,d2    ;is right shift key down?
  101.     bne    ck1x        ;br if leading edge on right shift
  102. *
  103. *  trailing edge on left shift--exit constrain mode
  104. *
  105.     clr.w    constrain
  106.     bra    ck0x
  107. *
  108. ck1x:
  109.     move.w    #-1,constrain
  110. *
  111. *  check ALT key
  112. *
  113. *  fathold =    0 if ALT not down
  114. *        2 if down
  115. *           -1 if leading edge down
  116. *        1 if trailing edge up
  117. ck0x:
  118.     btst.l    #ALT,d5        ;any edges
  119.     beq    ck20x        ;br if none
  120.     moveq    #1,d0        ;assume trailing
  121.     btst.l    #ALT,d2
  122.     beq    ck21x
  123.     moveq    #-1,d0
  124.     bra    ck21x
  125. ck20x:
  126.     moveq    #0,d0        ;assume no activity
  127.     btst.l    #ALT,d2        ;up or down
  128.     beq    ck21x
  129.     moveq    #2,d0
  130. ck21x:
  131.     move.w    d0,fathold
  132. *
  133. *   Now do CTRL key check..
  134. *
  135. ck2x:
  136.     tst.w    GridLock    ;check for grid lock on
  137.     beq    ck0off        ;if grid lock is off--check manual
  138. *
  139.     tst.w    grid        ;is this grid-init?
  140.     bpl    ck0on        ;init grid if not done already
  141.     bra    ck10        ;else, just continue grid
  142. ck0off:
  143.     btst.l    #CTRL,d5    ;edge on CTRL?
  144.     beq    ck10        ;br if no--do nothing
  145. *
  146.     clr.w    grid        ;assume clear grid
  147.     btst.l    #CTRL,d2    ;is left shift key down?
  148.     beq    ck10        ;br if trailing edge on left shift
  149. ck0on:
  150.     move.w    #1,grid        ;enter grid mode
  151. *
  152. ck10:
  153.     movem.l    (sp)+,a0/d0-d4
  154.     rts    
  155. *
  156. *****************************************************
  157. *
  158. *
  159. *    Some Subs for y'all
  160. *
  161. *
  162. *
  163. *
  164. *************************************************
  165. *
  166. *   Cookie cut stamp to Screen, clipped by our clipping variables
  167. *
  168. *    d0 = screen DST x
  169. *    d1 = screen DST y
  170. *    d2 = width
  171. *    d3 = height
  172. *    d4 = mono mask scr_nxln
  173. *
  174. *    a0 -> mono mask s_form (or color if rect fill)
  175. *    a3 -> 4-plane graphics s_form
  176. *    a5 -> current wstruct
  177. bdisplay:
  178. *
  179. *  Fill intermediate mask with all 1's
  180. *
  181. *
  182.     lea    grafmsk,a1
  183.     moveq    #-1,d7
  184.     move.w    d2,d5
  185.     add.w    #15,d5
  186.     and.w    #$fff0,d5
  187.     lsr.w    #3,d5
  188.     move.w    d5,d6
  189. *
  190.     mulu    d3,d6        ;d5 = # of bytes in mono-mask
  191.     lsr.w    #2,d6        ;d5 = # of longwords to init (cy = 1 if add word) 
  192.     bra    maskini
  193. maskinit:
  194.     move.l    d7,(a1)+
  195. maskini:
  196.     dbra    d6,maskinit
  197.     move.l    d7,(a1)+
  198.     move.w    d7,(a1)+
  199. maskd:
  200. *
  201. *  intermediate mask is full of 1's
  202. *
  203. *
  204.     movem.l    a0/a3/a5/d0-d5,-(sp)
  205. *
  206. *  do we need to blit from world mask to intermediate?
  207. *
  208.     sub.w    wx(a5),d0        ;adjust for window in screen
  209.     add.w    xoffset(a5),d0    ;d0 = d_xmin in world
  210.     cmp.w    w_wid(a5),d0    ;are we entirely to right of world?
  211.     bge    skipint        ;br if so--skip intermediate mono-mask blt
  212. *
  213.     sub.w    wy(a5),d1
  214.     add.w    yoffset(a5),d1
  215.     cmp.w    w_hite(a5),d1    ;are we entirely below world?
  216.     bge    skipint        ;br if so
  217. *
  218. *  We need to blit into intermediate mask
  219. *
  220.     lea    mask2i,a6    ;use world mask to intermediate blit
  221.     move.w    d5,d_nxln(a6)
  222. *
  223.     bsr    worldclp    ;clip for the world
  224.     movem.w    d0-d1,s_xmin(a6)
  225.     movem.w    d2-d3,b_width(a6)
  226.     movem.w    d5-d6,d_xmin(a6)
  227. *
  228. *  We set some durables here until get get our act together..
  229. *
  230.     move.l    worldmsk,s_form(a6)
  231.     move.l    #grafmsk,d_form(a6)
  232.     move.w    #2,d_nxwd(a6)
  233.     clr.w    d_nxpl(a6)
  234. *    
  235.     move.w    w_wrap,d0
  236.     lsr.w    #2,d0
  237.     move.w    d0,s_nxln(a6)
  238.     move.w    #2,s_nxwd(a6)
  239.     move.w    #0,s_nxpl(a6)
  240. *
  241.     move.l    #$01010101,op_tab(a6)    ;D' = S and D
  242.     move.w    #1,plane_ct(a6)
  243.     .dc.w    bitblt            ;blit mono to intermediate
  244. skipint:
  245.     movem.l    (sp)+,a0/a3/a5/d0-d5
  246. *
  247.     move.w    d3,d7        ;height to d7
  248. *
  249. *  Now, using intermediate mono-mask, build intermediate grafix buffer
  250. *
  251.     movem.l    a0/a3/a5/d0-d5,-(sp)    ;we need some regs
  252. *
  253.     lea    grafmsk,a1    ;get mask ptr
  254.     lea    grafbsh,a4    ;get grafix DST ptr
  255. *
  256.     lsr.w    #1,d4        ;# of words/mono scanline
  257.     beq    ofillpe        ;br if doing fill rectangle
  258. *
  259.     subq.w    #1,d4
  260.     bra    ormsklpi
  261. ormsklp0:
  262.     moveq    #2,d2
  263. ormsklp1:
  264.     move.w    d4,d0
  265.     move.l    a1,a2
  266. ormsklp2:    
  267.     move.w    (a3)+,d1    ;get graphics
  268.     and.w    (a2)+,d1
  269.     move.w    d1,(a4)+
  270.     dbra    d0,ormsklp2
  271.     dbra    d2,ormsklp1
  272. *
  273.     move.w    d4,d0        ;do last (#3) plane
  274.     move.l    a1,a2
  275. ormsklp3:
  276.     move.w    (a3)+,d1    ;get graphics
  277.     move.w    (a2),d3
  278.     and.w    d3,d1
  279.     move.w    d1,(a4)+
  280.     and.w    (a0)+,d3
  281.     move.w    d3,(a2)+
  282.     dbra    d0,ormsklp3
  283.     move.l    a2,a1        ;go on to next line of mask
  284. ormsklpi:
  285.     dbra    d7,ormsklp0
  286. *
  287.     bra    ormasko        ;skip over fill rectangle stuff
  288. *
  289. *  This is for filled rectangles
  290. *
  291. ofillpe:
  292.     sub.l    a3,a0        ;get color from offset
  293.     move.l    a0,d6        ; of mask
  294. *
  295.     move.w    d5,d4
  296.     lsr.w    #1,d4        ;# of words/mono scanline
  297.     subq.w    #1,d4
  298.     bra    ofillpi
  299. ofillp0:
  300.     moveq    #0,d2
  301. ofillp1:
  302.     moveq    #0,d5
  303.     btst.l    d2,d6
  304.     beq    ofillp1a
  305.     moveq    #-1,d5
  306. ofillp1a:
  307.     move.w    d4,d0
  308.     move.l    a1,a2
  309. ofillp2:    
  310.     move.w    d5,d1        ;get graphics
  311.     and.w    (a2)+,d1
  312.     move.w    d1,(a4)+
  313.     dbra    d0,ofillp2
  314.     addq.w    #1,d2
  315.     cmpi.w    #3,d2
  316.     bcs    ofillp1
  317. *
  318. *
  319.     moveq    #0,d5
  320.     btst.l    d2,d6
  321.     beq    ofillp2a
  322.     moveq    #-1,d5
  323. ofillp2a:
  324.     move.w    d4,d0        ;do last (#3) plane
  325.     move.l    a1,a2
  326. ofillp3:
  327.     move.w    d5,d1        ;get graphics
  328.     move.w    (a2),d3
  329.     and.w    d3,d1
  330.     move.w    d1,(a4)+
  331.     move.w    d3,(a2)+
  332.     dbra    d0,ofillp3
  333.     move.l    a2,a1        ;go on to next line of mask
  334. ofillpi:
  335.     dbra    d7,ofillp0
  336. *
  337. *
  338. ormasko:
  339.     movem.l    (sp)+,a0/a3/a5/d0-d5    ;get our regs back
  340. *
  341. *
  342. *  Now adjust d0-d3 for window clip..
  343. *
  344.     lea    bitblock,a6
  345.     move.w    d5,s_nxln(a6)    ;we need to save d5 here
  346. *
  347. *  check left clip
  348. *
  349.     moveq    #0,d5        ;assume 0 = s_xmin
  350.     cmp.w    xmin_clp,d0    ;check for left clip
  351.     bge    leffok
  352.     move.w    d0,d5
  353.     move.w    xmin_clp,d0
  354.     sub.w    d0,d5
  355.     neg.w    d5    
  356.     sub.w    d5,d2
  357. leffok:
  358. *
  359. *  check right clip
  360. *
  361.     move.w    d0,d7
  362.     add.w    d2,d7    ;find right-most position of block (+1)
  363.     cmp.w    xmax_clp,d7
  364.     ble    rittok    ;br if doesn't exceed max
  365.     sub.w    xmax_clp,d7
  366.     sub.w    d7,d2
  367. rittok:
  368. *
  369. *  check top clip
  370. *
  371.     moveq    #0,d6        ;assume 0 = s_ymin
  372.     cmp.w    ymin_clp,d1    ;check for top clip
  373.     bge    toppok
  374.     move.w    d1,d6
  375.     move.w    ymin_clp,d1
  376.     sub.w    d1,d6
  377.     neg.w    d6    
  378.     sub.w    d6,d3
  379. toppok:
  380. *
  381. *  check bottom clip
  382. *
  383.     move.w    d1,d7
  384.     add.w    d3,d7    ;find bottom-most position of block (+1)
  385.     cmp.w    ymax_clp,d7
  386.     ble    bottok    ;br if doesn't exceed max
  387.     sub.w    ymax_clp,d7
  388.     sub.w    d7,d3
  389. bottok:
  390. *
  391. *  
  392. *    d0 = d_xmin
  393. *    d1 = d_ymin
  394. *    d2 = b_width
  395. *    d3 = b_height
  396. *
  397. *    d5 = s_xmin
  398. *    d6 = s_ymin
  399. *
  400. *   Now clipped for window (given by clipping rectagle xmin_clp etc.)
  401. *
  402. *  Now BLT to screen
  403. *
  404. *
  405.     movem.w    d0-d1,d_xmin(a6)
  406.     movem.w    d2-d3,b_width(a6)
  407.     movem.w    d5-d6,s_xmin(a6)
  408. *
  409.     clr.l    p_addr(a6)        ;*** this could be durable ***
  410.     move.l    #grafmsk,s_form(a6)    ;*** this could be durable ***
  411.     move.w    #2,s_nxwd(a6)        ;*** this could be durable ***
  412.     clr.w    s_nxpl(a6)        ;*** this could be durable ***
  413.     move.l    #$04040404,op_tab(a6)
  414. *
  415.     bsr    copyund        ;copy graphics under sprite 1st
  416. *
  417.     move.w    #4,plane_ct(a6)
  418. *
  419.     movem.l    a0/a3/a5/a6,-(sp)
  420.     .dc.w    bitblt        ;cookie cut a hole
  421.     movem.l    (sp)+,a0/a3/a5/a6
  422. *
  423.     move.l    #grafbsh,s_form(a6)    ;get graphics to OR into hole
  424.     move.l    #$07070707,op_tab(a6)
  425.     move.w    #4,plane_ct(a6)
  426.     move.w    s_nxln(a6),d0
  427.     move.w    d0,s_nxpl(a6)
  428.     add.w    d0,d0
  429.     add.w    d0,d0
  430.     move.w    d0,s_nxln(a6)
  431. *
  432.     movem.l    a0/a3/a5/a6,-(sp)
  433.     .dc.w    bitblt        ;OR graphics into hole
  434.     movem.l    (sp)+,a0/a3/a5/a6
  435.     rts
  436. *
  437. *
  438. *
  439. *  
  440. *   Cookie cut stamp to World, world-clipped.
  441. *
  442. *
  443. *  It is assumed that wbblock (the blt parm block used) is properly
  444. *    set-up for the world buffer as destination
  445. *
  446. *    d0 = DST x
  447. *    d1 = DST y
  448. *    d2 = width
  449. *    d3 = height
  450. *    d4 = mono mask scr_nxln
  451. *
  452. *    a0 -> mono mask s_form
  453. *    a3 -> 4-plane graphics s_form
  454. *
  455. *
  456. wldblit:
  457.     lea    wbblock,a6        ;use DST: world bitBLT block
  458. *
  459.     clr.w    s_nxpl(a6)
  460.     move.w    #2,s_nxwd(a6)
  461. *
  462.     move.w    d4,s_nxln(a6)
  463.     bne    wldblit0    ;br if not a rect fill
  464. *
  465.     cmp.l    #grafbsh,a3    ;is rect fill from expanded buffer? 
  466.     bne    wldblit3    ;br if not
  467. *
  468.     move.w    d2,d4
  469.     addi.w    #15,d4
  470.     andi.w    #$fff0,d4
  471.     lsr.w    #3,d4
  472.     move.w    d4,s_nxln(a6)
  473.     bra    wldblit0
  474. *
  475. wldblit3:
  476.     clr.w    s_nxwd(a6)
  477.     move.l    a3,s_form(a6)
  478.     bra    wldblit1    
  479. wldblit0:    
  480.     move.l    a0,s_form(a6)
  481. wldblit1:
  482.     bsr    worldclp
  483.     movem.w    d0-d1,d_xmin(a6)
  484.     movem.w    d2-d3,b_width(a6)
  485.     movem.w    d5-d6,s_xmin(a6)
  486. *
  487.     move.l    #$04040404,op_tab(a6)
  488.     move.w    #4,plane_ct(a6)
  489.     clr.l    p_addr(a6)
  490. *
  491.     movem.l    a0/a3/a5/a6,-(sp)
  492.     .dc.w    bitblt        ;cookie cut a hole
  493.     movem.l    (sp)+,a0/a3/a5/a6
  494. *
  495.     move.l    a3,s_form(a6)    ;get graphics to OR into hole
  496.     move.l    #$07070707,op_tab(a6)
  497.     move.w    #4,plane_ct(a6)
  498.     move.w    s_nxln(a6),d0
  499.     move.w    d0,s_nxpl(a6)
  500.     add.w    d0,d0
  501.     add.w    d0,d0
  502.     move.w    d0,s_nxln(a6)
  503.     bne    wldblit2
  504.     move.l    #$05050707,op_tab(a6)
  505.     move.l    a0,d0
  506.     sub.l    a3,d0
  507.     move.w    d0,fg_col(a6)
  508.     clr.w    bg_col(a6)
  509. wldblit2:
  510. *
  511.     movem.l    a0/a3/a5/a6,-(sp)
  512.     .dc.w    bitblt        ;OR graphics into hole
  513.     movem.l    (sp)+,a0/a3/a5/a6
  514.     rts
  515. *
  516. *
  517. *
  518. *
  519. *
  520. *
  521. *  Check world clip
  522. *
  523. *   Entry:
  524. *    It is assumed that some part of the destination rectangle
  525. *    falls within the world.
  526. *
  527. *    a6 -> bit block
  528. *
  529. *    d0    = d_xmin    relative to world
  530. *    d1    = d_ymin
  531. *    d2    = b_width
  532. *    d3    = b_height
  533. *    w_wid    = width of world in pixels
  534. *    w_hite    = height of world in pixels
  535. *
  536. *   Exit:
  537. *    d0-d3 are set for proper clip,  d5-d6 are s_xmin, s_ymin
  538. *
  539. worldclp:
  540. *
  541. *  check left clip
  542. *
  543.     moveq    #0,d5        ;assume 0 = s_xmin
  544.     tst.w    d0        ;check for left clip
  545.     bge    leffokw
  546.     move.w    d0,d5
  547.     moveq    #0,d0
  548.     neg.w    d5    
  549.     sub.w    d5,d2
  550. leffokw:
  551. *
  552. *  check right clip
  553. *
  554.     move.w    d0,d7
  555.     add.w    d2,d7    ;find right-most position of block (+1)
  556.     sub.w    w_wid(a5),d7
  557.     ble    rittokw    ;br if doesn't exceed max
  558.     sub.w    d7,d2
  559. rittokw:
  560. *
  561. *  check top clip
  562. *
  563.     moveq    #0,d6        ;assume 0 = s_ymin
  564.     tst.w    d1    ;check for top clip
  565.     bge    toppokw
  566.     move.w    d1,d6
  567.     moveq    #0,d1
  568.     neg.w    d6    
  569.     sub.w    d6,d3
  570. toppokw:
  571. *
  572. *  check bottom clip
  573. *
  574.     move.w    d1,d7
  575.     add.w    d3,d7    ;find bottom-most position of block (+1)
  576.     sub.w    w_hite(a5),d7
  577.     ble    bottokw    ;br if doesn't exceed max
  578.     sub.w    d7,d3
  579. bottokw:
  580. *    move.w    d3,b_height(a6)
  581.     rts
  582. *
  583. **********************************************
  584. *
  585. *
  586. *  Toggle from original palette to that of 0th brush
  587. *
  588. switchpal:
  589.     bchg    #0,butt
  590.     bne    switch1
  591.     pea    oldpal
  592.     bra    switch2
  593. *
  594. *  Enter here from Palette change routine
  595. *
  596. switch1:
  597.     lea    palblock,a0
  598.     move.w    firstpal,d0
  599.     bmi    switch2a
  600.     lsl.w    #5,d0
  601.     adda.w    d0,a0
  602.     move.l    a0,-(sp)
  603. switch2:
  604.     move.w    #6,-(sp)
  605.     trap    #14        ;just restore old palette for now
  606.     addq.l    #6,sp
  607. switch2a:
  608. *    bsr    getmouse    ;d0=x,d1=y,d2=keycntrl,d3=mouse buttons
  609. *    andi.w    #1,d3
  610. *    bne    switch2a
  611.     rts
  612. *
  613. *
  614. *********************************************************
  615. *
  616. *   Check keyboard for any key that has come in
  617. *    and re-prioritize if key commands it.
  618. *
  619. checkpri:
  620.     movem.l    d0-d3/a0/a3,-(sp)    ;we need to preserve these
  621. *
  622.     ror.w    #8,d4        ;swap hi/lo bytes of key codes
  623. *
  624.     movem.w    bsh_x,d0-d3    ;get our rectangle
  625. *
  626.     sub.w    wx(a5),d0        ;adjust for world co-ords
  627.     add.w    xoffset(a5),d0
  628.     sub.w    wy(a5),d1
  629.     add.w    yoffset(a5),d1
  630. *
  631.     add.w    d0,d2        ;d2 = right edge +1
  632.     add.w    d1,d3        ;d3 = bottom edge +1
  633. *
  634.     move.l    wblkptr,a0    ;get highest priority obj ptr 
  635.     move.l    wblkcur,a1    ;    current
  636.     lea    worldblk,a2    ;    lowest
  637.     lea    bshblock,a3
  638. *
  639.     cmpi.b    #CLEAR_HOME,d4
  640.     beq    top_pri
  641.     cmpi.b    #INSERT,d4
  642.     beq    bot_pri
  643.     cmpi.b    #VERT_BAR,d4
  644.     beq    up_pri
  645.     cmpi.b    #KEYPAD4,d4
  646.     beq    down_pri
  647. *
  648.     cmpi.b    #FUNC_1,d4
  649.     bcs    notafunc
  650.     cmpi.b    #FUNC_10,d4
  651.     bls    do_func
  652. *
  653.     cmpi.b    #SH_FUNC_1,d4
  654.     bcs    notafunc
  655.     cmpi.b    #SH_FUNC_10,d4
  656.     bls    do_unfunc
  657. *
  658. notafunc:
  659.     ror.w    #8,d4        ;check for Hflip, Vflip
  660.     cmpi.b    #"a",d4
  661.     bcs    notax
  662.     subi.b    #$20,d4        ;make upper case
  663. notax:
  664.     cmpi.b    #"H",d4        ;want Hflip?
  665.     beq    dohflip        ;do H-flip
  666.     cmpi.b    #"V",d4        ;
  667.     beq    dovflip
  668.     cmpi.b    #"G",d4        ;want to toggle gridlock?
  669.     beq    dogridlk
  670.     cmpi.b    #"A",d4        ;how about alternate
  671.     beq    doalt
  672. *
  673. *  any other keys go here
  674. *
  675. chkprix:
  676.     movem.l    (sp)+,d0-d3/a0/a3
  677.     rts
  678. *
  679. *
  680. *
  681. dogridlk:
  682.     eori.w    #1,GridLock
  683.     bne    gridlk0
  684.     clr.w    grid
  685. gridlk0:
  686.     move.w    #-1,forceupd
  687.     bra    chkprix
  688. *
  689. *   Make the selected object the highest priority in the local neighborhood
  690. *
  691. top_pri:
  692.     moveq    #1,d7        ;init overlap count in d7
  693.     moveq    #0,d6        ;init our priority in d6
  694.     swap    d6        ; we need reg for temp use
  695.     bra    next_top
  696. top_lp:
  697.     move.w    -(a0),d5    ;get next objects ypos
  698.     move.w    -(a0),d4    ;xpos
  699.     sub.l    #2,a0        ;skip special effects
  700.     move.w    -(a0),d6    ;brush #
  701. *
  702.     cmp.w    d2,d4    ;check right edge of current with left edge of test
  703.     bge    next_top    ;br if current entirely to left of test
  704. *
  705.     cmp.w    d3,d5    ;check bottom edge of current with top edge of test
  706.     bge    next_top    ;br if current entirely above test
  707. *
  708.     lsl.w    #4,d6        ;index into bshblock
  709.     add.w    (a3,d6.w),d4    ;get right edge (+1) of object
  710.     add.w    2(a3,d6.w),d5    ;get bottom edge (+1) of object
  711. *
  712.     cmp.w    d0,d4    ;check left edge of current with right edge of test
  713.     ble    next_top    ;br if current entirely to right of test
  714. *
  715.     cmp.w    d1,d5    ;check top edge of current with bottom edge of test
  716.     ble    next_top    ;br if current entirely below test
  717. *
  718. *  We have overlap
  719. *
  720.     swap    d6        ;have we set the priority already?
  721.     tst.w    d6
  722.     bne    top_lp1        ;br if so
  723.     move.l    a0,d4
  724.     addq.l    #8,d4
  725.     move.w    d7,d6        ;
  726.     move.l    d4,wblkcur    ;adjust priority
  727. top_lp1:
  728.     swap    d6
  729.     addq.w    #1,d7
  730. *    
  731. next_top:
  732.     cmp.l    a0,a2        ;have we reached bottom priority?
  733.     bcs    top_lp        ;br if not
  734.     moveq    #1,d6
  735.     swap    d6
  736. re_prix:
  737.     swap    d6        ;d6 is count where priority was changed
  738. *
  739.     lea    priorma,a1
  740.     move.w    d6,d0
  741.     bsr    decitpad
  742. *
  743.     move.w    #"0",d0
  744. re_prix2:
  745.     cmp.b    -(a1),d0
  746.     bhi    re_prix2
  747.     addq.l    #1,a1
  748.     move.b    #" ",(a1)+
  749.     move.b    #"o",(a1)+
  750.     move.b    #"f",(a1)+
  751.     move.b    #" ",(a1)+
  752.     move.w    d7,d0        ;put out total count
  753.     bsr    decitpad
  754.     clr.b    (a1)+
  755. *
  756.     lea    priormsg,a0
  757.     move.w    #LIBRARY,d0
  758.     bsr    DaveInfo
  759. *
  760.     bsr    makemsk
  761.     move.w    #-1,forceupd    ;update this thing
  762. *    move.l    mouseptr,a0
  763. *    addq.w    #1,(a0)
  764. *    subq.w    #1,bsh_x
  765. re_prix1:
  766.     bra    chkprix
  767. *
  768. *
  769. *   Make the selected object the lowest priority in the local neighborhood
  770. *
  771. bot_pri:
  772.     moveq    #1,d7        ;init overlap count in d7
  773.     moveq    #0,d6        ;init our priority in d6
  774.     swap    d6        ; we need reg for temp use
  775.     bra    next_bot
  776. bot_lp:
  777.     move.w    (a2)+,d6    ;get next objects brush #
  778.     addq.w    #2,a2        ;skip special effects
  779.     move.w    (a2)+,d4    ;xpos
  780.     move.w    (a2)+,d5    ;ypos
  781. *
  782.     cmp.w    d2,d4    ;check right edge of current with left edge of test
  783.     bge    next_bot    ;br if current entirely to left of test
  784. *
  785.     cmp.w    d3,d5    ;check bottom edge of current with top edge of test
  786.     bge    next_bot    ;br if current entirely above test
  787. *
  788.     lsl.w    #4,d6        ;index into bshblock
  789.     add.w    (a3,d6.w),d4    ;get right edge (+1) of object
  790.     add.w    2(a3,d6.w),d5    ;get bottom edge (+1) of object
  791. *
  792.     cmp.w    d0,d4    ;check left edge of current with right edge of test
  793.     ble    next_bot    ;br if current entirely to right of test
  794. *
  795.     cmp.w    d1,d5    ;check top edge of current with bottom edge of test
  796.     ble    next_bot    ;br if current entirely below test
  797. *
  798. *  We have overlap
  799. *
  800.     swap    d6
  801.     tst.w    d6
  802.     bne    bot_lp1
  803.     move.w    d7,d6
  804.     move.l    a2,d4
  805.     subq.l    #8,d4
  806.     move.l    d4,wblkcur    ;adjust priority
  807. bot_lp1:
  808.     swap    d6
  809.     addq.w    #1,d7
  810. next_bot:
  811.     cmp.l    a0,a2        ;have we reached top priority?
  812.     bcs    bot_lp        ;br if not    
  813.     move.w    d7,d6
  814.     swap    d6
  815.     bra    re_prix
  816. *
  817. *
  818. *
  819. *   Bump down the selected object's priority in the local neighborhood
  820. *
  821. down_pri:
  822.     moveq    #1,d7
  823.     moveq    #0,d6
  824.     swap    d6
  825.     bra    next_Top
  826. *
  827. Top_lp:
  828.     move.w    -(a0),d5    ;get next objects ypos
  829.     move.w    -(a0),d4    ;xpos
  830.     sub.l    #2,a0        ;skip special effects
  831.     move.w    -(a0),d6    ;brush #
  832. *
  833.     cmp.w    d2,d4    ;check right edge of current with left edge of test
  834.     bge    next_Top    ;br if current entirely to left of test
  835. *
  836.     cmp.w    d3,d5    ;check bottom edge of current with top edge of test
  837.     bge    next_Top    ;br if current entirely above test
  838. *
  839.     lsl.w    #4,d6        ;index into bshblock
  840.     add.w    (a3,d6.w),d4    ;get right edge (+1) of object
  841.     add.w    2(a3,d6.w),d5    ;get bottom edge (+1) of object
  842. *
  843.     cmp.w    d0,d4    ;check left edge of current with right edge of test
  844.     ble    next_Top    ;br if current entirely to right of test
  845. *
  846.     cmp.w    d1,d5    ;check top edge of current with bottom edge of test
  847.     ble    next_Top    ;br if current entirely below test
  848. *
  849. *  We have overlap
  850. *
  851.     addq.w    #1,d7
  852.     swap    d6        ;have we set the priority already?
  853.     tst.w    d6
  854.     bne    Top_lp1        ;br if so
  855.     cmp.l    a0,a1
  856.     bls    Top_lp1
  857.     move.w    d7,d6        ;
  858.     move.l    a0,wblkcur    ;adjust priority
  859. Top_lp1:
  860.     swap    d6
  861. *    
  862. next_Top:
  863.     cmp.l    a0,a2        ;have we reached bottom priority?
  864.     bcs    Top_lp        ;br if not
  865.     swap    d6
  866.     tst.w    d6
  867.     bne    Top_lp3
  868.     move.w    d7,d6
  869. Top_lp3:
  870.     swap    d6
  871.     bra    re_prix
  872. *
  873. *
  874. *   Bump up the selected object's priority in the local neighborhood
  875. *
  876. up_pri:
  877.     moveq    #1,d7        ;init overlap count in d7
  878.     moveq    #0,d6        ;init our priority in d6
  879.     swap    d6        ; we need reg for temp use
  880.     bra    next_Bot
  881. Bot_lp:
  882.     move.w    (a2)+,d6    ;get next objects brush #
  883.     addq.w    #2,a2        ;skip special effects
  884.     move.w    (a2)+,d4    ;xpos
  885.     move.w    (a2)+,d5    ;ypos
  886. *
  887.     cmp.w    d2,d4    ;check right edge of current with left edge of test
  888.     bge    next_Bot    ;br if current entirely to left of test
  889. *
  890.     cmp.w    d3,d5    ;check bottom edge of current with top edge of test
  891.     bge    next_Bot    ;br if current entirely above test
  892. *
  893.     lsl.w    #4,d6        ;index into bshblock
  894.     add.w    (a3,d6.w),d4    ;get right edge (+1) of object
  895.     add.w    2(a3,d6.w),d5    ;get bottom edge (+1) of object
  896. *
  897.     cmp.w    d0,d4    ;check left edge of current with right edge of test
  898.     ble    next_Bot    ;br if current entirely to right of test
  899. *
  900.     cmp.w    d1,d5    ;check top edge of current with bottom edge of test
  901.     ble    next_Bot    ;br if current entirely below test
  902. *
  903. *  We have overlap
  904. *
  905.     addq.w    #1,d7
  906.     swap    d6
  907.     tst.w    d6
  908.     bne    Bot_lp1
  909.     cmp.l    a2,a1
  910.     bcc    Bot_lp1
  911.     move.w    d7,d6
  912.     move.l    a2,wblkcur    ;adjust priority
  913. Bot_lp1:
  914.     swap    d6
  915. next_Bot:
  916.     cmp.l    a0,a2        ;have we reached top priority?
  917.     bcs    Bot_lp        ;br if not
  918.     swap    d6
  919.     tst.w    d6
  920.     bne    Bop_lp3
  921.     move.w    d7,d6
  922. Bop_lp3:
  923.     move.w    d7,d0
  924.     sub.w    d6,d0
  925.     move.w    d0,d6
  926.     addq.w    #1,d6
  927.     swap    d6
  928.     bra    re_prix
  929. *
  930. *
  931. *
  932. *********************************************
  933. *
  934. *  Horizontal flip request on curbrush
  935. *
  936. dohflip:
  937.     bsr    makehflp    ;take curbrush, hflip and stuff in curbrush
  938. *
  939.     bra    doflip
  940. *
  941. *
  942. **********************************************
  943. *
  944. *
  945. *  Vertical flip request on curbrush
  946. *
  947. dovflip:
  948.     bsr    makevflp
  949. doflip:
  950.     move.w    curbrush,d0
  951.     bsr    upname        ;put up the name
  952.     bra    donew_bsh    ;exit thru brush display
  953. *
  954. *
  955. **************************************************
  956. *
  957. *
  958. doalt:
  959.     bsr    makealt
  960.     bra    doflip
  961. *
  962. *
  963. *   Take curbrush and build new curbrush (if not existing) that's lightened
  964. *
  965. makealt:    
  966.     lea    bshblock,a0
  967. *
  968.     move.w    curbrush,d0        ;check intrinsic or not
  969.     move.w    maxintrins,d1
  970.     cmp.w    d1,d0            ;are we?
  971.     bhi    aderivd            ;br if derived
  972. *
  973. *  We're an intrinsic brush--search derived brushes for existing hflip
  974. *
  975.     bra    doa1
  976. doa0:
  977.     lsl.w    #4,d1
  978.     move.l    8(a0,d1.w),a1        ;get derived ptr
  979.     lsr.w    #4,d1
  980. *
  981.     tst.w    4(a1)            ;check for non-cluster
  982.     bne    doa1            ;br if cluster
  983.     move.l    6(a1),d2        ;get brush # & effect
  984.     cmpi.w    #Alternate,d2        ;is this an Hflip?
  985.     bne    doa1
  986.     swap    d2
  987.     cmp.w    d2,d0            ;is this Hflip of our brush
  988.     beq    doa2            ;br if so
  989. doa1:    
  990.     addq.w    #1,d1
  991.     cmp.w    maxderivd,d1
  992.     bls    doa0
  993. *
  994. *  existing not available--better make a new one
  995. *
  996.     bsr    bsh_alt
  997. *
  998.     move.w    maxderivd,d1
  999.     bra    doa2
  1000. *
  1001. *  We're a derived brush--see if what we want is an intrinsic
  1002. *
  1003. aderivd:
  1004.     lsl.w    #4,d0
  1005.     move.l    8(a0,d0.w),a1    ;get derived ptr for curbrush
  1006.     lsr.w    #4,d0
  1007. *
  1008.     tst.w    4(a1)        ;check for non-cluster
  1009.     beq    doa2x        ;br if non-cluster
  1010.     move.w    d0,d2
  1011.     swap    d2
  1012.     clr.w    d2
  1013.     bra    aderv0    
  1014. doa2x:
  1015.     move.l    6(a1),d2    ;get 1st brush # & effect
  1016.     cmpi.w    #Alternate,d2    ;can we just go back to intrinsic?
  1017.     bne    aderv0        ;br if this alternate is not intrinsic
  1018.     swap    d2
  1019.     move.w    d2,d1
  1020.     bra    doa2
  1021. *
  1022. *  d1 = maxintrins
  1023. *
  1024. aderv0:
  1025.     eori.w    #Alternate,d2    ;see if we can find this derived
  1026.     move.l    d2,d0
  1027. *
  1028. *  search derived brushes for desired hflip
  1029. *
  1030.     bra    doa11
  1031. doa10:
  1032.     lsl.w    #4,d1
  1033.     move.l    8(a0,d1.w),a1        ;get derived ptr
  1034.     lsr.w    #4,d1
  1035. *
  1036.     tst.w    4(a1)        ;check for non-cluster
  1037.     bne    doa11        ;br if cluster
  1038.     move.l    6(a1),d2    ;get brush # & effect
  1039.     cmp.l    d0,d2        ;is this same effect & brush as desired
  1040.     beq    doa2        ;br if so--needn't derive
  1041. doa11:
  1042.     addq.w    #1,d1
  1043.     cmp.w    maxderivd,d1
  1044.     bls    doa10
  1045. *
  1046. *  existing not available--better make a new one
  1047. *
  1048.     move.l    d0,-(sp)    ;save intrinsic brush & effects
  1049.     bsr    bsh_alt
  1050.     move.w    maxderivd,d1
  1051.     move.l    (sp)+,d0
  1052.     move.w    d1,d2
  1053.     lsl.w    #4,d2
  1054.     move.l    8(a0,d2.w),a1
  1055.     move.l    d0,6(a1)    ;put in intrinsic brush & effects
  1056. *
  1057. *  this is what we want--existing derived available
  1058. *
  1059. doa2:
  1060.     move.w    d1,curbrush
  1061.     rts
  1062. *    
  1063. *
  1064. *
  1065. *
  1066. *   Take curbrush and build new curbrush (if not existing) that's hflipp'd
  1067. *
  1068. makehflp:    
  1069.     lea    bshblock,a0
  1070. *
  1071.     move.w    curbrush,d0        ;check intrinsic or not
  1072.     move.w    maxintrins,d1
  1073.     cmp.w    d1,d0            ;are we?
  1074.     bhi    hderivd            ;br if derived
  1075. *
  1076. *  We're an intrinsic brush--search derived brushes for existing hflip
  1077. *
  1078.     bra    doh1
  1079. doh0:
  1080.     lsl.w    #4,d1
  1081.     move.l    8(a0,d1.w),a1        ;get derived ptr
  1082.     lsr.w    #4,d1
  1083. *
  1084.     tst.w    4(a1)            ;check for non-cluster
  1085.     bne    doh1            ;br if cluster
  1086.     move.l    6(a1),d2        ;get brush # & effect
  1087.     cmpi.w    #Hflip,d2        ;is this an Hflip?
  1088.     bne    doh1
  1089.     swap    d2
  1090.     cmp.w    d2,d0            ;is this Hflip of our brush
  1091.     beq    doh2            ;br if so
  1092. doh1:    
  1093.     addq.w    #1,d1
  1094.     cmp.w    maxderivd,d1
  1095.     bls    doh0
  1096. *
  1097. *  existing not available--better make a new one
  1098. *
  1099.     bsr    bsh_hflip
  1100. *
  1101.     move.w    maxderivd,d1
  1102.     bra    doh2
  1103. *
  1104. *  We're a derived brush--see if what we want is an intrinsic
  1105. *
  1106. hderivd:
  1107.     lsl.w    #4,d0
  1108.     move.l    8(a0,d0.w),a1    ;get derived ptr for curbrush
  1109.     lsr.w    #4,d0
  1110. *
  1111.     tst.w    4(a1)        ;check for non-cluster
  1112.     beq    doh2x        ;br if non-cluster
  1113.     move.w    d0,d2
  1114.     swap    d2
  1115.     clr.w    d2
  1116.     bra    hderv0    
  1117. doh2x:
  1118.     move.l    6(a1),d2    ;get 1st brush # & effect
  1119.     cmpi.w    #Hflip,d2    ;can we just go back to intrinsic?
  1120.     bne    hderv0        ;br if this hflip is not intrinsic
  1121.     swap    d2
  1122.     move.w    d2,d1
  1123.     bra    doh2
  1124. *
  1125. *  d1 = maxintrins
  1126. *
  1127. hderv0:
  1128.     eori.w    #Hflip,d2    ;see if we can find this derived
  1129.     move.l    d2,d0
  1130. *
  1131. *  search derived brushes for desired hflip
  1132. *
  1133.     bra    doh11
  1134. doh10:
  1135.     lsl.w    #4,d1
  1136.     move.l    8(a0,d1.w),a1        ;get derived ptr
  1137.     lsr.w    #4,d1
  1138. *
  1139.     tst.w    4(a1)        ;check for non-cluster
  1140.     bne    doh11        ;br if cluster
  1141.     move.l    6(a1),d2    ;get brush # & effect
  1142.     cmp.l    d0,d2        ;is this same effect & brush as desired
  1143.     beq    doh2        ;br if so--needn't derive
  1144. doh11:
  1145.     addq.w    #1,d1
  1146.     cmp.w    maxderivd,d1
  1147.     bls    doh10
  1148. *
  1149. *  existing not available--better make a new one
  1150. *
  1151.     move.l    d0,-(sp)    ;save intrinsic brush & effects
  1152.     bsr    bsh_hflip
  1153.     move.w    maxderivd,d1
  1154.     move.l    (sp)+,d0
  1155.     move.w    d1,d2
  1156.     lsl.w    #4,d2
  1157.     move.l    8(a0,d2.w),a1
  1158.     move.l    d0,6(a1)    ;put in intrinsic brush & effects
  1159. *
  1160. *  this is what we want--existing derived available
  1161. *
  1162. doh2:
  1163.     move.w    d1,curbrush
  1164.     rts
  1165.     
  1166. *
  1167. *
  1168. ***********************************************************
  1169. *
  1170. *
  1171. makevflp:
  1172.     lea    bshblock,a0
  1173. *
  1174.     move.w    curbrush,d0        ;check intrinsic or not
  1175.     move.w    maxintrins,d1
  1176.     cmp.w    d1,d0            ;are we?
  1177.     bhi    vderivd            ;br if derived
  1178. *
  1179. *  We're an intrinsic brush--search derived brushes for existing hflip
  1180. *
  1181.     bra    dov1
  1182. dov0:
  1183.     lsl.w    #4,d1
  1184.     move.l    8(a0,d1.w),a1        ;get derived ptr
  1185.     lsr.w    #4,d1
  1186. *
  1187.     tst.w    4(a1)            ;check for non-cluster
  1188.     bne    dov1            ;br if cluster
  1189.     move.l    6(a1),d2        ;get brush # & effect
  1190.     cmpi.w    #Vflip,d2        ;is this an Vflip?
  1191.     bne    dov1
  1192.     swap    d2
  1193.     cmp.w    d2,d0            ;is this Vflip of our brush
  1194.     beq    doh2            ;br if so
  1195. dov1:    
  1196.     addq.w    #1,d1
  1197.     cmp.w    maxderivd,d1
  1198.     bls    dov0
  1199. *
  1200. *  existing not available--better make a new one
  1201. *
  1202.     bsr    bsh_vflip
  1203. *
  1204.     move.w    maxderivd,d1
  1205.     bra    dov2
  1206. *
  1207. *  We're a derived brush--see if what we want is an intrinsic
  1208. *
  1209. vderivd:
  1210.     lsl.w    #4,d0
  1211.     move.l    8(a0,d0.w),a1    ;get derived ptr for curbrush
  1212.     lsr.w    #4,d0
  1213. *
  1214.     tst.w    4(a1)            ;check for non-cluster
  1215.     beq    dov2x            ;exit if cluster
  1216.     move.w    d0,d2
  1217.     swap    d2
  1218.     clr.w    d2
  1219.     bra    vderv0
  1220. dov2x:
  1221.     move.l    6(a1),d2    ;get brush # & effect
  1222.     cmpi.w    #Vflip,d2    ;can we just go back to intrinsic?
  1223.     bne    vderv0        ;br if this vflip is not intrinsic
  1224.     swap    d2
  1225.     move.w    d2,d1
  1226.     bra    dov2
  1227. *
  1228. *  d1 = maxintrins
  1229. *
  1230. vderv0:
  1231.     eori.w    #Vflip,d2    ;see if we can find this derived
  1232.     move.l    d2,d0
  1233. *
  1234. *  search derived brushes for desired hflip
  1235. *
  1236.     bra    dov11
  1237. dov10:
  1238.     lsl.w    #4,d1
  1239.     move.l    8(a0,d1.w),a1        ;get derived ptr
  1240.     lsr.w    #4,d1
  1241. *
  1242.     tst.w    4(a1)        ;check for non-cluster
  1243.     bne    dov11        ;br if cluster
  1244.     move.l    6(a1),d2    ;get brush # & effect
  1245.     cmp.l    d0,d2        ;is this same effect & brush as desired
  1246.     beq    dov2        ;br if so--needn't derive
  1247. *
  1248. dov11:
  1249.     addq.w    #1,d1
  1250.     cmp.w    maxderivd,d1
  1251.     bls    dov10
  1252. *
  1253. *  existing not available--better make a new one
  1254. *
  1255.     move.l    d0,-(sp)    ;save intrinsic brush # & effects
  1256.     bsr    bsh_vflip
  1257.     move.w    maxderivd,d1
  1258.     move.l    (sp)+,d0
  1259.     move.w    d1,d2
  1260.     lsl.w    #4,d2
  1261.     move.l    8(a0,d2.w),a1
  1262.     move.l    d0,6(a1)    ;put in intrinsic brush # & effects
  1263. *
  1264. *  this is what we want--existing derived available
  1265. *
  1266. dov2:
  1267.     move.w    d1,curbrush
  1268.     rts
  1269. *
  1270. *
  1271. *
  1272. *
  1273. *
  1274. *
  1275. *
  1276. *    Function Key stuff
  1277. *
  1278. do_func:
  1279.     moveq    #0,d0
  1280.     move.b    d4,d0
  1281.     subi.b    #FUNC_1,d0    
  1282.     lsl.w    #8,d0
  1283.     bsr    Func_Key    ;install new curbrush
  1284. *
  1285. donew_bsh:
  1286. *
  1287.     bsr    pastund        ;erase old brush
  1288. *
  1289.     movem.l    a1/d4-d7,-(sp)
  1290.     movem.w    bsh_x,d0-d3
  1291.     lsr.w    #1,d2
  1292.     lsr.w    #1,d3
  1293.     add.w    d2,d0
  1294.     add.w    d3,d1        ;d0-d1 is raw x/y
  1295. *
  1296.     lea    bshblock,a1        ;get brush data block base
  1297.     move.w    curbrush,d2        ;get desired brush #
  1298.     lsl.w    #4,d2
  1299. *
  1300.     adda.w    d2,a1
  1301.     move.w    (a1)+,d2        ;get block width
  1302.     move.w    d2,bsh_wid        ;save for use by move
  1303. *
  1304.     move.w    d2,d5            ;copy width
  1305.     lsr.w    #1,d5
  1306.     sub.w    d5,d0            ;adjust xpos by 1/2 width
  1307. *
  1308.     move.w    d0,bsh_x        ;we allow bsh_x < 0
  1309. *
  1310. *
  1311.     move.w    (a1)+,d3        ;get block height
  1312.     move.w    d3,bsh_hite        ;save for use by move
  1313. *
  1314.     move.w    d3,d6
  1315.     lsr.w    #1,d6
  1316.     sub.w    d6,d1
  1317. *
  1318.     move.w    d1,bsh_y
  1319. *
  1320.     move.l    (a1)+,a3    ;a3 -> s_form
  1321.     move.l    a3,a0
  1322.     addq.l    #4,a1        ;skip obj_name string
  1323. *    move.l    (a1)+,a2    ;object name string
  1324. *
  1325.     move.w    (a1)+,d4    ;get mask_offset
  1326.     lea    (a3,d4.w),a0    ;get mono mask src_form
  1327. *
  1328.     move.w    (a1)+,d4    ;s_nxln for 4-plane brush
  1329.     lsr.w    #2,d4        ;d4 = mono scr_nxln
  1330.     move.w    d4,bsh_monoln
  1331. *
  1332. *
  1333. *    d0 = DST x
  1334. *    d1 = DST y
  1335. *    d2 = width
  1336. *    d3 = height
  1337. *    d4 = mono mask scr_nxln
  1338. *
  1339. *    a0 -> mono mask s_form
  1340. *    a3 -> 4-plane graphics s_form
  1341. *
  1342. *
  1343.     bsr    bdisplay    ;display brush, clipped to screen
  1344.     movem.l    (sp)+,a1/d4-d7
  1345. *
  1346. *chkprix:
  1347. *    movem.l    (sp)+,d0-d3/a0/a3
  1348.     movem.l    (sp)+,d0-d3
  1349.     addq.l    #8,sp        ;allow a0 & a3 to be updated
  1350.     rts
  1351. *
  1352. *
  1353. *
  1354. do_unfunc:
  1355.     moveq    #0,d0
  1356.     move.b    d4,d0
  1357.     subi.b    #SH_FUNC_1,d0    
  1358.     lsl.w    #8,d0
  1359.     bsr    Shift_Func_Key
  1360.     bra    chkprix        ;exit--no change
  1361. *
  1362. *
  1363. *   Copy a patch of the screen sufficient for the next
  1364. *    screen blt to be undone when pastund is called.
  1365. *
  1366. *    a6 -> BLT parm block
  1367. *
  1368. copyund:
  1369.     movem.l    a0-a1/d0-d3,-(sp)
  1370. *
  1371. *    moveq    #$f0,d3        ;assembler doesn't like this
  1372. *
  1373.     move.w    #$fff0,d3    ;get our mask ready
  1374.     move.l    d_form(a6),a0    ;get base ptr of screen
  1375.     move.w    d_nxln(a6),d0    ;d0 = line width
  1376.     move.w    d0,d1        ;save in d1 to find span
  1377.     mulu    d_ymin(a6),d0    ;* ypos to give offset to top line
  1378.     add.l    d0,a0        ;add to ptr
  1379. *
  1380.     move.w    d_xmin(a6),d0    ;find adjust due to x component
  1381.     move.w    b_width(a6),d2
  1382.     add.w    d0,d2
  1383.     subq.w    #1,d2
  1384. *
  1385.     and.w    d3,d0
  1386.     and.w    d3,d2
  1387.     sub.w    d0,d2
  1388.     lsr.w    #4,d2    ;d2 = width of block in double long words (-1)
  1389. *
  1390.     lsr.w    #1,d0
  1391.     adda.w    d0,a0        ;a0-> 1st word to transfer
  1392.     move.l    a0,undform
  1393. *
  1394.     move.w    d2,d0
  1395.     addq.w    #1,d0
  1396.     lsl.w    #3,d0
  1397.     sub.w    d0,d1        ;d1 = line length - span
  1398.  
  1399.     move.w    b_height(a6),d0    ;get height of blt
  1400.     subq.w    #1,d0
  1401. *
  1402. *    d0 = undhite (# scanlines high -1)
  1403. *    d1 = undspan (# bytes to finish screen span)
  1404. *    d2 = undwid  (# of double long words in splat line -1)
  1405. *
  1406.     movem.w    d0-d2,undhite
  1407. *
  1408.     lea    undbuf,a1
  1409. cund0:
  1410.     move.w    d2,d3
  1411. cund1:
  1412.     move.l    (a0)+,(a1)+
  1413.     move.l    (a0)+,(a1)+
  1414.     dbra    d3,cund1
  1415. *
  1416.     adda.w    d1,a0
  1417.     dbra    d0,cund0
  1418. *
  1419. *
  1420.     movem.l    (sp)+,a0-a1/d0-d3    
  1421.     rts
  1422. *
  1423. *
  1424. *
  1425. *
  1426. pastund:
  1427.     movem.l    a0-a1/d0-d3,-(sp)
  1428.     movem.w    undhite,d0-d2
  1429. *    
  1430. *
  1431. *    d0 = undhite (# scanlines high -1)
  1432. *    d1 = undspan (# bytes to finish screen span)
  1433. *    d2 = undwid  (# of double long words in splat line -1)
  1434. *
  1435. *
  1436.     tst.w    d0        ;check for no und here
  1437.     bmi    pundx        ;exit if no und to do
  1438. *
  1439.     lea    undbuf,a0
  1440.     move.l    undform,a1
  1441. pund0:
  1442.     move.w    d2,d3
  1443. pund1:
  1444.     move.l    (a0)+,(a1)+
  1445.     move.l    (a0)+,(a1)+
  1446.     dbra    d3,pund1
  1447. *
  1448.     adda.w    d1,a1
  1449.     dbra    d0,pund0
  1450. *
  1451. *
  1452. pundx:
  1453.     movem.l    (sp)+,a0-a1/d0-d3    
  1454.     rts
  1455. *
  1456. *  Build a library
  1457. *
  1458. makelib:
  1459.     move.l    library,a0    ;first, clear out library buffer
  1460.     lea    wstruct+lxoffset,a5
  1461.     lea    libblock,a1
  1462.     bra    mwldi
  1463. *
  1464. *
  1465. **************************************************************8
  1466. *
  1467. *   Build a new world (and mask) from the data in the world block
  1468. *
  1469. *
  1470. *  uses wblkptr for worldblk end indicator
  1471. *    wblkcur for current priority in worldblk
  1472. *    w_wid, w_hite for world size info
  1473. *
  1474. makewld:
  1475.     move.l    world,a0    ;first, clear out world buffer
  1476.     lea    wstruct,a5
  1477.     lea    worldblk,a1
  1478. mwldi:
  1479.     move.l    a1,-(sp)    ;save ptr to begining of world entries
  1480. *
  1481.     move.w    w_wid(a5),d0
  1482.     move.w    d0,old_wid    ;save last width used to build world
  1483.     addi.w    #15,d0
  1484.     andi.w    #$fff0,d0
  1485.     lsr.w    #1,d0        ;d0 = world form_width
  1486.     move.w    d0,w_wrap    ;save in world wrap
  1487.     move.w    d0,old_wrap    ;save last wrap
  1488. *
  1489.     lsr.w    #3,d0        ;get # of words in line of mask
  1490.     move.w    w_hite(a5),d1
  1491.     move.w    d1,old_hite    ;save last height used to build world
  1492.     mulu    d1,d0        ;* # of lines = worlds in mask
  1493. *
  1494.     move.l    a0,-(sp)
  1495.     moveq    #0,d1
  1496.     bra    clworli
  1497. clworl0:
  1498.     swap    d0
  1499. clworl:
  1500.     move.l    d1,(a0)+    ;world initialized
  1501.     move.l    d1,(a0)+
  1502. clworli:    
  1503.     dbra    d0,clworl
  1504.     swap    d0
  1505.     dbra    d0,clworl0
  1506. *
  1507.     move.l    (sp)+,a0    
  1508. *
  1509.     move.l    a0,-(sp)
  1510.     move.w    w_wrap,d0
  1511.     mulu    w_hite(a5),d0
  1512.     add.l    d0,a0
  1513.     move.l    a0,worldmsk    ;since we know the size of the world,
  1514. *                ; we know where worldmsk begins
  1515.     lsr.l    #2,d0        ;size of worldmsk is 1/4 of world
  1516.     add.l    d0,a0
  1517.     addq.l    #8,a0        ;we may overshoot mask by 8 bytes
  1518. *
  1519.     move.l    a0,derivdgraf    ;save ptr for derived graphics
  1520. *
  1521.     move.l    (sp)+,a0
  1522. *
  1523. *  Now put all the stamps in the world buffer..
  1524. *
  1525. *
  1526. *  Load up durable bshblock to world BitBlt parms..
  1527. *
  1528.     lea    wbblock,a6    ;world build bitblt
  1529.     move.l    a0,d_form(a6)
  1530. *
  1531.     move.w    w_wrap,d_nxln(a6)
  1532.     move.w    #8,d_nxwd(a6)
  1533.     move.w    #2,d_nxpl(a6)
  1534. *
  1535.     move.w    #2,s_nxwd(a6)
  1536. *
  1537.     lea    bshblock,a2
  1538. *
  1539. *    Do we need a floor tile?
  1540. *
  1541.     move.w    worldtile,d2    ;check world tile
  1542.     bmi    nowtile        ;br if no tile to worry about
  1543. *
  1544. *   Yes, we tile this time
  1545. *
  1546.     lsl.w    #4,d2        ;*16 to get index into brush block
  1547.     lea    (a2,d2.w),a4    ;ptr to bshblock entry
  1548. *
  1549.     movem.w    initxtile,d0-d1        ;get initial d_xmin,d_ymin
  1550.     movem.w    d0-d1,rowxtile        ;save row start position
  1551.     movem.w    (a4)+,d2-d3        ;get width & height
  1552.     move.l    (a4)+,s_form(a6)    ;graphics SRC form
  1553.     addq.l    #6,a4            ;skip id_string, mono-mask offset 
  1554.     move.w    (a4)+,d4        ;get s_nxln
  1555.     move.w    d4,s_nxln(a6)
  1556.     lsr.w    #2,d4
  1557.     move.w    d4,s_nxpl(a6)
  1558. *
  1559.     move.l    #$07070707,op_tab(a6)    ;or mode for tile
  1560.     bra    tilelpi
  1561. tilelp:
  1562.     movem.l    d0-d3/a5/a6,-(sp)
  1563.     bsr    worldclp    ;clip to the world
  1564.     movem.w    d0-d1,d_xmin(a6)
  1565.     movem.w    d2-d3,b_width(a6)
  1566.     movem.w    d5-d6,s_xmin(a6)
  1567.     move.w    #4,plane_ct(a6)
  1568.     .dc.w    bitblt
  1569.     movem.l    (sp)+,d0-d3/a5/a6
  1570. *
  1571. *  calculate position of next item to right in row
  1572. *
  1573. nextcol:
  1574.     add.w    d2,d0
  1575. *
  1576.     add.w    rowthoff,d0
  1577.     add.w    rowtvoff,d1
  1578. *
  1579. tilelpi:
  1580.     bsr    worldon        ;is it on the world?
  1581.     beq    tilelp        ;br if so
  1582. *
  1583. *  off the world--keep going in this row until off to right
  1584. *
  1585.     btst.l    #0,d4        ;have we gone too far right?
  1586.     beq    nextcol        ;continue until we are
  1587. *
  1588. *  at end of row
  1589. *
  1590.     btst.l    #2,d4        ;are we below
  1591.     beq    nextrow        ;br if not
  1592. *
  1593. *  we are below and to right-- is rowtvoff negative?
  1594. *
  1595.     tst.w    rowtvoff    ;check for upslope on row
  1596.     bmi    tiledone    ;we're done if so
  1597. *
  1598. nextrow:
  1599. *
  1600. *  calculate position of next item down in leftmost column
  1601. *
  1602.     movem.w    rowxtile,d0-d1
  1603. *
  1604.     add.w    d3,d1
  1605.  
  1606.     add.w    colthoff,d0
  1607.     add.w    coltvoff,d1
  1608. *
  1609. *  check for xpos > 0
  1610. *
  1611. colchk:
  1612.     tst.w    d0
  1613.     blt    xnextok
  1614. *
  1615. *  do a negative row thang
  1616. *
  1617.     sub.w    d2,d0
  1618. *
  1619.     sub.w    rowthoff,d0
  1620.     sub.w    rowtvoff,d1
  1621.     bra    colchk
  1622. xnextok:
  1623. *
  1624. *
  1625.     movem.w    d0-d1,rowxtile
  1626. *
  1627.     bsr    worldon
  1628.     beq    tilelp        ;br if on the world
  1629. *
  1630.     btst.l    #2,d4        ;did we go below?
  1631.     beq    nextcol        ;br if not--just do next item in this row
  1632. *
  1633.     tst.w    rowtvoff    ;test for downslope on row
  1634.     bmi    nextcol
  1635. *
  1636. tiledone:
  1637. *
  1638. *  we're done
  1639. *
  1640. nowtile:
  1641. *
  1642.     move.l    (sp)+,a1    ;reget ptr to begining of world
  1643. *
  1644. *    lea    worldblk,a1    ;get pointer to begining of world blk
  1645. *
  1646.     lea    bshblock,a2
  1647.     bra    makwldi
  1648. makwld:
  1649.     movem.w    (a1)+,d2-d3    ;get brush #, effects,
  1650.     movem.w    (a1)+,d0-d1    ; & hpos, vpos
  1651. *
  1652. *  ignore effects for now
  1653. *
  1654.     cmp.w    maxderivd,d2    ;did we exceed max brush #?
  1655.     bhi    makwldi        ;br if so--this one's not available
  1656. *    
  1657.     lsl.w    #4,d2        ;*16 to get index into brush block
  1658.     lea    (a2,d2.w),a4    ;ptr to bshblock entry
  1659. *
  1660.     movem.w    (a4)+,d2-d3    ;get width & height
  1661.     move.l    (a4)+,a3    ;graphics SRC form
  1662.     move.l    a3,a0
  1663.     addq.l    #4,a4        ;skip id_string
  1664.     adda.w    (a4)+,a0    ;add offset to make mono mask SRC form base
  1665.     move.w    (a4)+,d4
  1666.     lsr.w    #2,d4        ;get mono_mask s_nxln
  1667. *
  1668.     movem.l    a1-a2/a5,-(sp)
  1669.     bsr    wldblit        ;stuff into world
  1670.     movem.l    (sp)+,a1-a2/a5
  1671. *
  1672. makwldi:
  1673.     cmp.l    wblkptr,a1    ;reached end yet?
  1674.     bcs    makwld        ;br if not.
  1675.  
  1676.     rts            ;we finished the world
  1677. *
  1678. *
  1679. *   Generate the world mask buffer using wblkcur as priority indicator
  1680. *
  1681. *    This routine is called whenever priority is changed
  1682. *
  1683. makemsk:
  1684. *
  1685. *  clear the mask (put in all 1's)
  1686. *
  1687.     move.l    worldmsk,a0
  1688.     lea    wstruct,a5
  1689.     move.w    w_wid(a5),d0
  1690.     addi.w    #15,d0
  1691.     andi.w    #$fff0,d0
  1692.     lsr.w    #1,d0        ;d0 = world form_width
  1693.     move.w    d0,w_wrap    ;save in world wrap
  1694. *
  1695.     mulu    w_hite(a5),d0    ;# of bytes in world graphics form
  1696.     lsr.l    #5,d0        ;get # of double longwords in world mask form
  1697.     addq.l    #1,d0
  1698. *
  1699.     moveq    #-1,d1
  1700.     bra    setmski
  1701. setmsk0:
  1702.     swap    d0
  1703. setmsk:
  1704.     move.l    d1,(a0)+
  1705.     move.l    d1,(a0)+
  1706. setmski:    
  1707.     dbra    d0,setmsk    ;this may do up to 8 bytes too many    
  1708. *                 but who cares with this speed
  1709. *
  1710.     swap    d0
  1711.     dbra    d0,setmsk0
  1712. *
  1713. *   Now do bshblock to world_mask BLT's
  1714. *
  1715.     move.l    wblkcur,a0    ;get pointer to current priority
  1716. *
  1717. *  Load up durable bshblock to world_mask BitBlt parms..
  1718. *
  1719.     lea    wbmblock,a6    ;world mask build bitblt
  1720.     move.l    worldmsk,d_form(a6)
  1721. *
  1722.     move.w    w_wrap,d0
  1723.     lsr.w    #2,d0
  1724.     move.w    d0,d_nxln(a6)
  1725.     move.w    #2,d_nxwd(a6)
  1726.     move.w    #0,d_nxpl(a6)
  1727. *
  1728. *
  1729.     move.w    #0,s_nxpl(a6)
  1730. *
  1731.     move.l    #$04040404,op_tab(a6)    ;D' = [not S] and D
  1732.     clr.l    p_addr(a6)
  1733.     lea    bshblock,a2
  1734.     bra    makmski
  1735. makmsk:
  1736.     movem.w    (a0)+,d2-d3    ;get brush #, effects
  1737.     movem.w    (a0)+,d0-d1    ; & hpos, vpos
  1738. *
  1739. *  ignore effects for now
  1740. *
  1741.     cmp.w    maxderivd,d2    ;did we exceed max brush #?
  1742.     bhi    makwldi        ;br if so--this one's not available
  1743. *    
  1744.     move.w    #2,s_nxwd(a6)    ;assume normal mask
  1745. *
  1746.     lsl.w    #4,d2        ;*16 to get index into brush block
  1747.     lea    (a2,d2.w),a3    ;ptr to bshblock entry
  1748. *
  1749.     movem.w    (a3)+,d2-d3    ;get width & height
  1750. *
  1751.     bsr    worldclp    ;clip to the world
  1752.     movem.w    d0-d1,d_xmin(a6)
  1753.     movem.w    d2-d3,b_width(a6)
  1754.     movem.w    d5-d6,s_xmin(a6)
  1755. *
  1756.     move.l    (a3)+,a4    ;a4 -> graphics form
  1757.     addq.l    #4,a3
  1758.     move.w    (a3)+,d0    ;d0 = mask offset (or color if filled rect)
  1759.  
  1760.     move.w    (a3)+,d1    ;get s_nxln
  1761.     lsr.w    #2,d1
  1762.     move.w    d1,s_nxln(a6)
  1763.     bne    makmsk1
  1764.     clr.w    s_nxwd(a6)
  1765.     bra    makmsk2
  1766. makmsk1:
  1767.     adda.w    d0,a4
  1768. makmsk2:
  1769.     move.l    a4,s_form(a6)
  1770. *
  1771.     move.w    #1,plane_ct(a6)
  1772.     movem.l    a0-a2/a5/a6,-(sp)
  1773.     .dc.w    bitblt
  1774.     movem.l    (sp)+,a0-a2/a5/a6
  1775. makmski:
  1776.     cmp.l    wblkptr,a0    ;reached end yet?
  1777.     bcs    makmsk        ;br if not.
  1778. *
  1779.     rts            ;else, we're done
  1780. *
  1781. *
  1782. *
  1783. *
  1784. *  see if tile is completely off the world..
  1785. *
  1786. *  d0,d1,d2,d3 is x,y,w,h
  1787. *
  1788. *   returns Z if within world
  1789. *        d4,d5 destroyed
  1790. *       NZ if outside world
  1791. *        d4 has bits set to indicate
  1792. *           where its outside:    b3 - vert all above
  1793. *                    b2 - vert all below
  1794. *                    b1 - horz all left
  1795. *                    b0 - horz all right
  1796. *
  1797. worldon:
  1798.     moveq    #0,d4
  1799.     cmp.w    w_wid(a5),d0    ;are we completely to right?
  1800.     blt    noffr        ;br if not
  1801.     bset.l    #0,d4
  1802. noffr:
  1803.     move.w    d0,d5        ;are we completely to left?
  1804.     add.w    d2,d5
  1805. *    subq.w    #1,d5
  1806. *    bpl    noffl        ;br if not
  1807.     bgt    noffl
  1808. *
  1809.     bset.l    #1,d4
  1810. noffl:
  1811.     cmp.w    w_hite(a5),d1    ;are we completely below
  1812.     blt    nottb        ;br if not
  1813.     bset.l    #2,d4
  1814. nottb:
  1815.     move.w    d1,d5
  1816.     add.w    d3,d5
  1817. *    subq.w    #1,d5
  1818. *    bpl    notta
  1819.     bgt    notta
  1820. *
  1821.     bset.l    #3,d4
  1822. notta:
  1823.     tst.w    d4
  1824.     rts
  1825. *
  1826. *
  1827. *
  1828. *
  1829. *
  1830. *
  1831. DaveClrWorld:
  1832.     movem.l    a0-a6/d0-d7,-(sp)
  1833.     lea    worldblk,a0
  1834.     move.l    a0,wblkptr
  1835.     move.l    a0,wblkcur
  1836. clearfloor:
  1837.     move.w    #-1,worldtile    ;indicate no world tile
  1838. reworld:
  1839.     bsr    makewld
  1840.     bsr    makemsk
  1841. *
  1842. *    dc.w    $a00a        ;hide mouse
  1843. *
  1844. *    movem.w    wx(a5),d0-d3
  1845. *    bsr    WindRefresh
  1846. *
  1847. *    dc.w    $a009        ;show mouse
  1848. *
  1849.     movem.l    (sp)+,a0-a6/d0-d7
  1850.     rts
  1851. *
  1852. *
  1853. *
  1854. DaveTile:
  1855.     movem.l    a0-a6/d0-d7,-(sp)
  1856.     move.w    curbrush,worldtile
  1857.     moveq    #0,d0
  1858.     move.l    d0,initxtile
  1859.     move.l    d0,rowthoff
  1860.     move.l    d0,colthoff        ;clear irregular stuff
  1861.     bra    reworld
  1862.  
  1863. DaveITile:
  1864.     movem.l    a0-a6/d0-d7,-(sp)
  1865.     move.w    curbrush,worldtile
  1866. *
  1867.     movem.w    Itile,d0-d5
  1868.     movem.w    d0-d5,initxtile
  1869. *    
  1870.     bra    reworld
  1871. *
  1872. NEW_BUT:
  1873.     tst    d0
  1874.     beq    place
  1875.     move.w    d0, BUT_STATE
  1876.     move.w    #1,d0            ; always return left button
  1877. place:
  1878.     move.l    BUT_ADDR,-(sp)
  1879.     rts                ; jmp to AES subroutine
  1880. *
  1881. *
  1882. *
  1883. *  Routine for sizing the world width and height
  1884. *
  1885. *     whenever this is called, derived graphics must be adjusted
  1886. *
  1887. DaveSize:
  1888.     movem.l    a0-a6/d0-d7,-(sp)
  1889.     lea    wstruct,a5
  1890.     movem.w    w_wid(a5),d4-d5        ;get new width & height
  1891. *
  1892. DSz0:
  1893.     bsr    adjsize        ;adjust buffers for new world
  1894.     beq    DSz1        ;br if A-ok
  1895.     movem.w    d4-d5,-(sp)    ;save proposed size
  1896.     bsr    TooBigRam    ;ask user what to do
  1897.     movem.w    (sp)+,d4-d5
  1898.     tst.w    d0
  1899.     bne    DSz0        ;retry with new
  1900.     movem.w    old_wid,d4-d5
  1901. *
  1902. DSz1:
  1903.     movem.w    d4-d5,wstruct+w_wid
  1904. *
  1905. *    Now, remove objects that fall off the new world..
  1906. *
  1907.     lea    worldblk,a0        ;remove objects that fall off new    
  1908.     move.l    wblkptr,a1        ;world
  1909.     move.l    wblkcur,a2
  1910.     bra    newsizi
  1911. newsizlp:
  1912.     movem.w    (a0)+,d0-d3    ;get next entry
  1913.     cmp.w    d2,d4        ;is this object off right side?
  1914.     ble    offobj        ;br if so--object is out 'o this world
  1915.     cmp.w    d3,d5
  1916.     bgt    newsizi
  1917. *
  1918. *   remove the wholly clipped object
  1919. *
  1920. offobj:
  1921.     cmp.l    a0,a2        ;is current priority object affected?
  1922.     bcs    offobj0        ;br if current priority object not affected 
  1923.     subq.l    #8,a2        ;else, adjust current priority object
  1924. offobj0:
  1925.     movem.l    a0/a2,-(sp)
  1926.     lea    -8(a0),a2
  1927. offobj1:
  1928.     move.l    (a0)+,(a2)+
  1929.     move.l    (a0)+,(a2)+
  1930.     cmp.l    a1,a2
  1931.     bcs    offobj1    
  1932.     movem.l    (sp)+,a0/a2
  1933.     subq.l    #8,a0
  1934.     subq.l    #8,a1
  1935. newsizi:
  1936.     cmp.l    a1,a0
  1937.     bcs    newsizlp
  1938.     move.l    a1,wblkptr
  1939.     move.l    a2,wblkcur
  1940.     bra    reworld        ;exit thru reworld
  1941. *
  1942. *
  1943. *
  1944. *
  1945. *
  1946. *  Entry:
  1947. *   d4 = proposed world width
  1948. *   d5 = proposed world height
  1949. *
  1950. *  Exit:
  1951. *    d0 = 0 if new size is approved and buffers rearranged
  1952. *    d0 = -1 if too big to fit, no change done; d4-d5 are sized to fit
  1953. *
  1954. adjsize:
  1955. *
  1956. *    Adjust derived graphics buffer placement & touch up all
  1957. *    derived graphics pointers..
  1958. *
  1959.     move.w    d4,d0
  1960.     addi.w    #15,d0
  1961.     andi.w    #$fff0,d0
  1962.     lsr.w    #1,d0        ;determine new wrap
  1963.     mulu    d5,d0        ;d0 = new world size
  1964.     move.l    d0,d1
  1965.     lsr.l    #2,d1
  1966.     addq.l    #8,d1        ;d1 = new world's mask size
  1967.     add.l    d1,d0        ;d0 = total ram requirements for new world
  1968. *
  1969.     move.l    derivdend,d1
  1970.     move.l    derivdgraf,d6    ;d6 = base of derived graphics
  1971.     sub.l    d6,d1        ;d1 = total dervided ram requirements
  1972. *
  1973.     move.l    world,d2    ;d2 = base of world
  1974.     move.l    d2,d3
  1975.     add.l    d0,d3
  1976.     add.l    d1,d3
  1977.     cmp.l    malloend,d3    ;are we exceeding RAM allocation?
  1978.     bcs    sizeok        ;br if requested size is allowed
  1979. *
  1980. *   Size too big--find a good size that'll fit
  1981. *
  1982.     sub.l    malloend,d3    ;d3 = how much we should shave off
  1983.     add.l    #256,d3        ; give a little breathing room
  1984. *
  1985.     cmp.w    d4,d5        ;which dimension is larger?
  1986.     bcc    hitebig        ;br if height is larger
  1987. *
  1988. *  width is larger
  1989. *
  1990.     move.w    d5,d0        ;copy hite to d0
  1991.     mulu    #10,d0        ;d0 = amount each word of width adds
  1992.     divu    d0,d3
  1993.     addq.w    #1,d3
  1994.     lsl.w    #4,d3        ;d3 = amount to subtract from width
  1995.     sub.w    d3,d4
  1996.     bra    sizenok
  1997. hitebig:
  1998.     move.w    d4,d0
  1999.     addi.w    #15,d0
  2000.     andi.w    #$fff0,d0
  2001.     lsr.w    #1,d0        ;re-determine wrap
  2002.     move.w    d0,d1
  2003.     lsr.w    #2,d1
  2004.     add.w    d1,d0        ;d0 = # of bytes needed/line of height
  2005.     divu    d0,d3
  2006.     addq.w    #1,d3
  2007.     sub.w    d3,d5
  2008. sizenok:
  2009.     moveq    #-1,d0
  2010.     rts
  2011. *
  2012. *   It fits, now adjust derived graphics ptrs
  2013. *
  2014. sizeok:
  2015.     move.l    d6,d3
  2016.     sub.l    d2,d3        ;get old world ram requirements
  2017. *
  2018. *    d0.l    - new world RAM requirements
  2019. *    d1.l    - derived graphics RAM requirements
  2020. *    d2.l    - base of world
  2021. *    d3.l    - old world RAM requirements
  2022. *
  2023. *
  2024. *    d6.l    - old base of derived graphics
  2025. *
  2026. *
  2027.     move.l    d0,d7
  2028.     sub.l    d3,d7        ;signed difference in RAM requirements
  2029.     beq    notouch        ;br if no derived graphics need move
  2030. *
  2031. *   Touch up all derived graphics ptrs
  2032. *
  2033.     lea    bshblock,a2
  2034.     move.w    maxintrins,d3
  2035.     bra    touchlpi
  2036. touchlp:
  2037.     lsl.w    #4,d3
  2038.     add.l    d7,4(a2,d3.w)    ;touch-up new base addr
  2039.     lsr.w    #4,d3
  2040. touchlpi:
  2041.     addq.w    #1,d3
  2042.     cmp.w    maxderivd,d3
  2043.     bls    touchlp
  2044. *
  2045.     add.l    d0,d2    ;d2 = new base of derived graphics
  2046. *
  2047.     move.l    d6,a0        ;old derived base
  2048.     move.l    d2,a1        ;new derived base
  2049.     move.l    a1,derivdgraf    ;save new ptr
  2050.     add.l    d1,d2
  2051.     move.l    d2,derivdend    ;save new end
  2052. *
  2053.     tst.l    d7    ;check for move up or down memory lane
  2054.     bpl    backup    ;br if we're expanding
  2055. *
  2056. *  We're contracting, use low ends
  2057. *
  2058.     lsr.l    #2,d1    ;# of longs in derived graphics (-1 or 0 adjust)
  2059.     bra    forlp0
  2060. forlp1:
  2061.     swap    d1
  2062. forlp0:
  2063.     move.l    (a0)+,(a1)+
  2064. forlpi:
  2065.     dbra    d1,forlp0
  2066.     swap    d1
  2067.     dbra    d1,forlp1
  2068. *
  2069.     bra    notouch        ;we're done
  2070. *
  2071. *  We're expanding, use high ends
  2072. *
  2073. backup:
  2074.     adda.l    d1,a0    ;old derived end (+1)
  2075.     adda.l    d1,a1    ;new derived end (+1)
  2076.     lsr.l    #2,d1    ;# of longs in derived graphics (-1 or 0 adjust)
  2077.     bra    backlp0
  2078. backlp1:
  2079.     swap    d1
  2080. backlp0:
  2081.     move.l    -(a0),-(a1)
  2082. backlpi:
  2083.     dbra    d1,backlp0
  2084.     swap    d1
  2085.     dbra    d1,backlp1
  2086. *
  2087. notouch:
  2088.     moveq    #0,d0
  2089.     rts
  2090. *
  2091. *
  2092. *
  2093. * New Grid Function - no inputs or outputs
  2094. * The new Grid Sizes are in the globals - gridx, gridy, gridw,gridh
  2095. DaveGrid:
  2096.        rts
  2097. *
  2098. *
  2099. * New Mouse Movement Vector Function
  2100. NEW_MOV:
  2101.     move.l    MOV_ADDR,-(sp)
  2102.     rts
  2103. *
  2104. *
  2105. * Will be calling the Irregular Tile Setup dialog box.
  2106. * This function must set the global variables.
  2107. *     TileText - string array for object name - 10 characters max
  2108. *     All below are ints - max 999, tell me if more is necessary
  2109. *     tilex
  2110. *     tiley
  2111. *     tilexrow
  2112. *     tileyrow
  2113. *     tilexcol
  2114. *     tileycol
  2115. ITileSetup:
  2116.     lea    Itile+12,a4
  2117. *
  2118. *  entry
  2119. *  a4 -> destination string
  2120. *
  2121. *  a2, a3
  2122. gstring:
  2123.     move.w    curbrush,d0
  2124.     ext.l    d0    
  2125.     lsl.l    #4,d0        ;*16 to get index into brush block
  2126.     lea    bshblock,a2
  2127.     adda.w    d0,a2
  2128.     move.l    8(a2),a3    ;ptr to id_string
  2129. *
  2130.     moveq    #10,d0        ;Cary sez only 11 chars allowed
  2131. itilp:
  2132.     move.b    (a3)+,d1
  2133.     cmpi.b    #" ",d1
  2134.     bls    itilpx
  2135.     move.b    d1,(a4)+
  2136.     dbra    d0,itilp
  2137. itilpx:
  2138.     clr.b    (a4)+
  2139. itiled:
  2140.     rts
  2141. *
  2142. *
  2143. *
  2144. GetCurObj:
  2145.     move.l    a0,a4
  2146.     bsr    gstring        ;copy object ID string to a0
  2147.     move.l    (a2),4(a1)    ;get width & height also
  2148.     rts
  2149. *
  2150. *
  2151. *
  2152. *
  2153. ClrFloor:
  2154.     movem.l    a0-a6/d0-d7,-(sp)
  2155.     bra    clearfloor
  2156. *
  2157. *
  2158. *
  2159. LoadPal:
  2160.     move.w    curbrush,d0
  2161.     cmp.w    maxintrins,d0
  2162.     bhi    loadpal0    
  2163.     move.w    d0,firstpal
  2164. loadpal0:
  2165.     bra    switch1
  2166. *
  2167. *
  2168. *
  2169. *  d0 = brush #
  2170. *  a0 -> bshblock
  2171. *
  2172. upname:
  2173.     movem.l    a0-a6/d0-d7,-(sp)
  2174.     bra    upn
  2175. *
  2176. * d0 - # of key ( 0 - 9 ) ( reads)
  2177. *
  2178. Func_Key:
  2179.     movem.l    a0-a6/d0-d7,-(sp)
  2180.     lsr.w    #7,d0
  2181.     lea    Func_Array,a0
  2182.     move.w    (a0,d0.w),d0
  2183.     cmp.w    maxderivd,d0
  2184.     bgt    funkey0        ;br if we can't take this
  2185. *
  2186.     lea    bshblock,a0
  2187.     lsl.w    #4,d0
  2188.     tst.w    (a0,d0.w)    ;are we a real brush
  2189.     beq    funkey0        ;br if not real
  2190. *
  2191.     lsr.w    #4,d0
  2192.     move.w    d0,curbrush
  2193. *
  2194. *  Put out name (are we derived)
  2195. *
  2196. upn:    
  2197.     lea    brshfile,a1
  2198.     move.w    d0,d1
  2199.     lsl.w    #4,d0
  2200.     adda.w    d0,a0
  2201.     move.l    8(a0),a0
  2202.  
  2203.     cmp.w    maxintrins,d1
  2204.     bls    oname
  2205. *
  2206. *  we are derived
  2207. *
  2208.     move.l    (a0),a0
  2209. oname:
  2210.     move.b    (a0)+,d0
  2211.     move.b    d0,(a1)+
  2212.     cmpi.b    #" ",d0
  2213.     bhi    oname
  2214.     clr.b    -(a1)
  2215.     lea    brshfile,a0
  2216.     move.w    #LIBRARY,d0
  2217.     bsr    DaveInfo        
  2218. funkey0:
  2219.     movem.l    (sp)+,a0-a6/d0-d7
  2220.     bsr    Back2G
  2221.     rts
  2222. *
  2223. *
  2224. *
  2225. *
  2226. *   We call this whenever we go back to Cary (curbrush : cluster check)
  2227. *
  2228. Back2G:
  2229.     movem.l    a0-a6/d0-d7,-(sp)
  2230.     move.w    curbrush,d1
  2231. Back0:
  2232.     moveq    #0,d0        ;assume non-cluster
  2233.     cmp.w    maxintrins,d1
  2234.     bls    Back1        ;br if intrinsic
  2235. *
  2236. *  we may be a cluster
  2237. *
  2238.     moveq    #1,d0        ;assume cluster
  2239.     lsl.w    #4,d1
  2240.     lea    bshblock,a0
  2241.     move.l    8(a0,d1.w),a1
  2242.     tst    4(a1)        ;are we a cluster?
  2243.     bne    Back1        ;br if so
  2244. *
  2245. *
  2246.     move.w    6(a1),d1    ;get next indirect brush
  2247.     bra    Back0    
  2248. Back1:
  2249.     bsr    SetCluster    ;set cluster active/inactive
  2250.     movem.l    (sp)+,a0-a6/d0-d7
  2251.     rts
  2252. *
  2253. *
  2254. *
  2255. * d0 - # of key ( 0 - 9 ) ( writes )
  2256. *
  2257. Shift_Func_Key:
  2258.     movem.l    a0-a6/d0-d7,-(sp)
  2259.     lsr.w    #7,d0
  2260.     lea    Func_Array,a0
  2261.     move.w    curbrush,(a0,d0.w)
  2262.     movem.l    (sp)+,a0-a6/d0-d7
  2263.     rts
  2264. *
  2265.